#include "led.h"
#include "ui_led.h"
#include <QDebug>

led::led(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::led)
{
    ui->setupUi(this);
    getLedState();
}

led::~led()
{
    delete ui;
}

void led::getLedState()
{
    file.setFileName("/sys/devices/platform/leds/leds/sys-led/brightness");

    if (!file.exists())
        return;

    if(!file.open(QIODevice::ReadWrite))
        qDebug()<<file.errorString();

    QTextStream in(&file);

    /* 读取文件所有数据 */
    QString buf = in.readLine();

    file.close();
    if (buf == "1") {
        ui->led_label->setText("开");
    } else {
        ui->led_label->setText("关");
    }
}

void led::on_backbt_clicked()
{
    this->close();
}

void led::on_pushButton_clicked()
{
    system("echo none > /sys/class/leds/sys-led/trigger");
    system("echo 1 > /sys/class/leds/sys-led/brightness");
    ui->led_label->setText("开");
}

void led::on_pushButton_2_clicked()
{
    system("echo none > /sys/class/leds/sys-led/trigger");
    system("echo 0 > /sys/class/leds/sys-led/brightness");
    ui->led_label->setText("关");
}
